//
// Created by liushuai on 2021/2/14.
//

#include "isPerfectSquare.h"
<<<<<<< HEAD:cxx/algorithm/src/isPerfectSquare.cc
bool isPerfectSquare(int num){
    int left = 1;
    int right = num;
    while(left<=right){
        int mid = (right-left)/2+left;
        if(mid>num/mid)
            right = mid-1;
        else if(mid == num/mid){
            if(num%mid==0)
                return true;
            else
                right = mid-1;
        }
        else
            left = mid+1;

    }
    return false;
}
bool isPerfectSquare1(int num){
    int base = 1;
    while(num>0){
        num -= base;
        base +=2;
    }
    return num == 0;
=======
bool isPerfectSquare(int num) {
  int left = 1;
  int right = num;
  while (left <= right) {
    int mid = (right - left) / 2 + left;
    if (mid > num / mid)
      right = mid - 1;
    else if (mid == num / mid) {
      if (num % mid == 0)
        return true;
      else
        right = mid - 1;
    } else
      left = mid + 1;
  }
  return false;
}
bool isPerfectSquare1(int num) {
  int base = 1;
  while (num > 0) {
    num -= base;
    base += 2;
  }
  return num == 0;
>>>>>>> dev:cxx/algorithm/common/src/isPerfectSquare.cc
}